dnl
dnl Hoard: A Fast, Scalable, and Memory-Efficient Allocator
dnl        for Shared-Memory Multiprocessors
dnl Contact author: Emery Berger, http://www.cs.utexas.edu/users/emery
dnl
dnl Copyright (c) 1998, 1999, The University of Texas at Austin.
dnl
dnl This library is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU Library General Public License as
dnl published by the Free Software Foundation, http://www.fsf.org.
dnl
dnl This library is distributed in the hope that it will be useful, but
dnl WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dnl Library General Public License for more details.
dnl

dnl Process this file with autoconf to produce a configure script.
dnl

AC_INIT(superblock.h)
AC_CONFIG_AUX_DIR(autoconf)
AC_PREREQ(2.13)dnl Minimum Autoconf version required.

AM_INIT_AUTOMAKE(libhoard, 2.0)

dnl Enable Features
AC_ARG_ENABLE(debug,
[  --enable-debug          Enable debugging. [default=no]],
debug=$enableval,
debug=no)
AM_CONDITIONAL(DEBUG, test X"$debug" = Xyes)

AC_ARG_ENABLE(privateheaps,
[  --enable-privateheaps   Enable private heaps. [default=no]],
privateheaps=$enableval,
privateheaps=no)
AM_CONDITIONAL(PRIVATEHEAPS, test X"$privateheaps" = Xyes)

AC_ARG_ENABLE(windowsnt,
[  --enable-windowsnt      Compile for Windows NT. [default=no]],
windowsnt=$enableval,
windowsnt=no)
AM_CONDITIONAL(WINDOWSNT, test X"$windowsnt" = Xyes)

AC_ARG_ENABLE(sproc,
[  --enable-sproc          Compile for SGI's sproc library. [default=no]],
sproc=$enableval,
sproc=no)
AM_CONDITIONAL(SPROC, test X"$sproc" = Xyes)

dnl Set C/C++ compiler debugging flags (should come before AC_PROG_CC)
if test "$debug" != "no"; then
    CFLAGS="$CFLAGS -g -DDEBUG"
    CXXFLAGS="$CXXFLAGS -g"
else
    CFLAGS="$CFLAGS -DNDEBUG"
    CXXFLAGS="$CXXFLAGS -DNDEBUG"
fi

dnl Checks for programs
AM_PROG_LIBTOOL
AC_PROG_CC
AC_PROG_CXX
AC_PROG_CPP
AC_PROG_INSTALL

dnl Checks for libraries
if test X"$sproc" = Xno; then
AC_CHECK_LIB(pthread, pthread_exit, LIBTHREAD1=-lpthread, LIBTHREAD1=)
AC_CHECK_LIB(thread, lwp_self, LIBTHREAD=-lthread, LIBTHREAD=$LIBTHREAD1)
AC_CHECK_LIB(posix4, sched_yield, LIBSCHED=-lposix4, LIBSCHED=)
fi

dnl Set C/C++ compiler specific warning/optimization flags
if test X"$GCC" = X"yes"; then	
    EXTRA_CXXFLAGS="-fno-exceptions"
    if test X"$debug" = X"no"; then 
       OPTFLAGS="-Wall -O6 -fexpensive-optimizations -finline-functions -fomit-frame-pointer -ffast-math"
    else
       OPTFLAGS="-Wall -g -fno-inline"
    fi
elif $CXX -V 2>&1 | grep "WorkShop"; then
    SUNWORKSHOP="yes"
    EXTRA_CXXFLAGS="-mt -noex"
    if test X"$debug" = X"no"; then
dnl -fast optimizes for current platofrm, e.g. builds 64bit what is
dnl compatible with 32 bit code ... other targets are ultra, or ultra3
        OPTFLAGS="-fast -xtarget=generic -O2 -dalign"
    else
        OPTFLAGS="-g"
    fi
else
    if test X"$debug" = X"no"; then
        OPTFLAGS="-O"
    else
        OPTFLAGS="-g"
    fi
fi

AM_CONDITIONAL(USE_WORKSHOP, test X"$SUNWORKSHOP" = Xyes)
CFLAGS="$CFLAGS -D_REENTRANT=1 $EXTRA_CFLAGS $OPTFLAGS"
CXXFLAGS="$CXXFLAGS -D_REENTRANT=1 $EXTRA_CXXFLAGS $OPTFLAGS"

if test X"$privateheaps" = Xyes; then
    AC_DEFINE(USE_PRIVATE_HEAPS, 1)
else
    AC_DEFINE(USE_PRIVATE_HEAPS, 0)
fi

if test X"$windowsnt" = Xyes; then
    AC_DEFINE(WIN32, 1)
fi

if test X"$sproc" = Xyes; then
    AC_DEFINE(USE_SPROC, 1)
else
    AC_DEFINE(USE_SPROC, 0)
fi

dnl Check to see if we're using Linux.
AC_MSG_CHECKING(for Linux)
AC_EGREP_CPP(yes,
[#if defined(__linux)
  yes
#endif
], is_linux=yes, is_linux=no)
AM_CONDITIONAL(USE_LINUX, test X"$is_linux" = Xyes)
AC_MSG_RESULT($is_linux)


dnl Check to see if we're using Solaris.
AC_MSG_CHECKING(for Solaris)
AC_EGREP_CPP(yes,
[#if defined(__SVR4)
  yes
#endif
], is_solaris=yes, is_solaris=no)
AM_CONDITIONAL(USE_SOLARIS, test X"$is_solaris" = Xyes)
AC_MSG_RESULT($is_solaris)


dnl Architecture-specific tests.
AC_MSG_CHECKING(for Intel x86)
AC_EGREP_CPP(yes,
[#if defined(i386)
  yes
#endif
], is_x86=yes, is_x86=no)
AM_CONDITIONAL(USE_X86, test X"$is_x86" = Xyes)
AC_MSG_RESULT($is_x86)

if test X"$is_x86" = "Xno"; then
AC_MSG_CHECKING(for SPARC)
AC_EGREP_CPP(yes,
[#if defined(sparc)
  yes
#endif
], is_sparc=yes, is_sparc=no)
AM_CONDITIONAL(USE_SPARC, test X"$is_sparc" = Xyes)
AC_MSG_RESULT($is_sparc)

if test X"$is_sparc" = "Xno"; then
AC_MSG_CHECKING(for Power PC)
AC_EGREP_CPP(yes,
[#if defined(ppc)
  yes
#endif
], is_ppc=yes, is_ppc=no)
AM_CONDITIONAL(USE_PPC, test X"$is_ppc" = Xyes)
AC_MSG_RESULT($is_ppc)
fi
fi


dnl Outputs
AC_SUBST(LIBTHREAD)
AC_SUBST(LIBSCHED)
AC_OUTPUT(Makefile benchmarks/consume/Makefile benchmarks/larson/Makefile benchmarks/linux-scalability/Makefile benchmarks/shbench/Makefile)

echo "Configuration done. Run make to build Hoard."

